package com.feeyin.radar.crm.controller;

import com.feeyin.radar.commons.Page;
import com.feeyin.radar.commons.StringUtils;
import com.feeyin.radar.crm.form.SaleFunnelForm;
import com.feeyin.radar.crm.service.SaleFunnelService;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

public class SaleFunnelController extends MultiActionController
{
  private SaleFunnelService saleFunnelService;
  private String saleFunnel;
  private String funnelCustomers;

  public SaleFunnelService getSaleFunnelService()
  {
    return this.saleFunnelService;
  }

  public void setSaleFunnelService(SaleFunnelService saleFunnelService) {
    this.saleFunnelService = saleFunnelService;
  }

  public String getSaleFunnel() {
    return this.saleFunnel;
  }

  public void setSaleFunnel(String saleFunnel) {
    this.saleFunnel = saleFunnel;
  }

  public String getFunnelCustomers() {
    return this.funnelCustomers;
  }

  public void setFunnelCustomers(String funnelCustomers) {
    this.funnelCustomers = funnelCustomers;
  }

  public ModelAndView display(HttpServletRequest request, HttpServletResponse response, SaleFunnelForm saleFunnelForm)
  {
    Map model = new HashMap();
    Integer userId = (Integer)request.getSession().getAttribute("userId");
    model.put("users", this.saleFunnelService.getDeptSalePersons(userId));
    model.put("saleStages", this.saleFunnelService.getSaleFunnel(userId, saleFunnelForm));
    model.put("saleFunnelForm", saleFunnelForm);
    return new ModelAndView(getSaleFunnel(), model);
  }

  public ModelAndView funnelCustomers(HttpServletRequest request, HttpServletResponse response, SaleFunnelForm saleFunnelForm)
  {
    Map model = new HashMap();
    Integer userId = (Integer)request.getSession().getAttribute("userId");
    String saleStageId = request.getParameter("saleStageId");
    model.put("saleStageId", saleStageId);
    model.put("saleFunnelForm", saleFunnelForm);
    if (!StringUtils.isEmpty(saleStageId)) {
      Page page = new Page();
      page.getPageList(this.saleFunnelService.getPageFunnelCustomersCount(Integer.valueOf(Integer.parseInt(saleStageId)), userId, saleFunnelForm).intValue(), Integer.valueOf(5), request);
      model.put("customers", this.saleFunnelService.getPageFunnelCustomers(Integer.valueOf(Integer.parseInt(saleStageId)), userId, saleFunnelForm, page));
    }
    return new ModelAndView(getFunnelCustomers(), model);
  }
}